{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-4">
    <h3 class="pb-3">薪资生成</h3>
    <table class="layui-table layui-table-form">
        <tr>
            <td colspan="16"><strong>薪资信息</strong></td>
        </tr>

        {notempty name="$admin"}

        {volist name="$admin" id="vo"}
        <tr>
            <td>
                <input type="text" value="{$vo.name}" name="names[]" readonly autocomplete="off" placeholder=""
                       class="layui-input">
            </td>
            <td>
                <input type="text" value="{$vo.department}" name="departments[]" readonly autocomplete="off" placeholder=""
                       class="layui-input">
            </td>
            <td class="layui-td-gray">薪资</td>
            <td>
                <input type="number" name="base_salarys[]" readonly value="{$vo.base_salary}" autocomplete="off"
                       lay-reqText="" placeholder="" class="layui-input">
            </td>
            <td class="layui-td-gray">五险</td>
            <td>
                <input type="number" name="insurance_deducts[]" readonly value="{$vo.insurance_deduct}" autocomplete="off"
                       placeholder=""
                       class="layui-input">
            </td>
            <td class="layui-td-gray">提成</td>
            <td>
                <input type="number" name="performances[]" value="{$vo.performance}" readonly value="" autocomplete="off"
                       placeholder=""
                       class="layui-input">
            </td>
            <td class="layui-td-gray">全勤</td>
            <td>
                <input type="number" name="checkings[]" value="0" autocomplete="off"
                       placeholder=""
                       class="layui-input checking">
            </td>
            <td class="layui-td-gray">补差</td>
            <td>
                <input type="number" name="allowances[]" value="0" autocomplete="off"
                       placeholder=""
                       class="layui-input allowance">
            </td>
            <td class="layui-td-gray">综合薪资</td>
            <td>
                <input type="number" name="moneys[]" value="{$vo.money}" readonly value="" autocomplete="off"
                       placeholder=""
                       class="layui-input money">
                <input type="hidden" value="{$vo.money}" class="money_zh">
            </td>
            <td class="layui-td-gray-2">备注</td>
            <td>
                <textarea name="remarks[]" placeholder="备注信息" class="layui-textarea"></textarea>
            </td>
            <input type="hidden" name="ids[]" value="{$vo.id}">
        </tr>
        {/volist}
        {/notempty}


    </table>
    <div class="py-3">
        <input type="hidden" name="title" value="{$title}">
        <input type="hidden" name="year" value="{$year}">
        <input type="hidden" name="month" value="{$month}">
        <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">一键生成</button>
    </div>
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
    const moduleInit = ['tool', 'employeepicker', 'oaTool'];

    function gouguInit() {
        var form = layui.form, tool = layui.tool, table = layui.table, laydate = layui.laydate, oaTool = layui.oaTool,
            employeepicker = layui.employeepicker;

        laydate.render({
            elem: '#handle_time',
            showBottom: false
        });

        $(".allowance").on("input",function(e){
            var checking = $(this).parents("tr").children().find('.checking').val();
            var money_zh = $(this).parents("tr").children().find('.money_zh').val();
            var money_input = $(this).parents("tr").children().find('.money');
            var new_money = parseFloat(e.delegateTarget.value)+parseFloat(money_zh)+parseFloat(checking);
            money_input.val(new_money);
        });
        $(".checking").on("input",function(e){
            var allowance = $(this).parents("tr").children().find('.allowance').val();
            var money_zh = $(this).parents("tr").children().find('.money_zh').val();
            var money_input = $(this).parents("tr").children().find('.money');
            var new_money = parseFloat(e.delegateTarget.value)+parseFloat(money_zh)+parseFloat(allowance);
            money_input.val(new_money);
        });
        //相关附件上传
        oaTool.addFile();
        //radio选择
        form.on('radio(tax)', function (data) {
            if (data.value == 0) {
                $('[name="tax"]').val('0').hide();
            } else {
                $('[name="tax"]').val('').show();
            }
        });

        //监听提交
        form.on('submit(webform)', function (data) {

            let callback = function (e) {
                layer.msg(e.msg);
                if (e.code == 0) {
                    tool.sideClose(1000);
                }
            }
            tool.post("/finance/salary/produce", data.field, callback);
            return false;
        });


        form.on('select(flowtype)', function (data) {
            var check_type = data.elem[data.elem.selectedIndex].title;
            var formHtml = '<td class="layui-td-gray">经办人<font>*</font></td>\
		<td colspan="5">\
			<input type="text" name="handle_person" value="" autocomplete="off" placeholder="请选择经办人" lay-verify="required" lay-reqText="请选择经办人" class="layui-input picker-one"><input type="hidden" name="handle_person_id" value="">\
		</td>';
            if (check_type == 2) {
                $('#flow_tr').html(formHtml);
                form.render();
            }
            if (data.value == '') {
                $('#flow_tr').html(formHtml);
                $('[name="copy_names"]').val('');
                $('[name="copy_uids"]').val('');
                form.render();
                return false;
            }
            $.ajax({
                url: "/api/index/get_flow_users",
                type: 'get',
                data: {id: data.value},
                success: function (e) {
                    if (e.code == 0) {
                        var flowLi = '';
                        var flow_data = e.data.flow_data;
                        if (e.data.copy_uids && e.data.copy_uids != '') {
                            $('[name="copy_names"]').val(e.data.copy_unames);
                            $('[name="copy_uids"]').val(e.data.copy_uids.split(','));
                        }
                        if (check_type == 1 || check_type == 3) {
                            for (var a = 0; a < flow_data.length; a++) {
                                var userList = '', sign_type = '';
                                if (check_type == 1) {
                                    if (flow_data[a].flow_type == 1) {
                                        userList += '<li style="padding:3px 0">当前部门负责人</li>';
                                    }
                                    else if (flow_data[a].flow_type == 2) {
                                        userList += '<li style="padding:3px 0">上级部门负责人</li>';
                                    }
                                    else {
                                        if (flow_data[a].flow_type == 3) {
                                            sign_type = ' <span class="layui-badge layui-bg-blue">或签</span>';
                                        }
                                        if (flow_data[a].flow_type == 4) {
                                            sign_type = ' <span class="layui-badge layui-bg-blue">会签</span>';
                                        }
                                        for (var b = 0; b < flow_data[a].user_id_info.length; b++) {
                                            userList += '<li style="padding:3px 0"><img src="' + flow_data[a].user_id_info[b].thumb + '" style="width:24px; height:24px; border-radius:50%; margin-right:8px;" />' + flow_data[a].user_id_info[b].name + '</li>';
                                        }
                                    }
                                }
                                else if (check_type == 3) {
                                    sign_type = ' <span class="layui-badge layui-bg-blue">' + flow_data[a].flow_name + '</span>'
                                    for (var b = 0; b < flow_data[a].user_id_info.length; b++) {
                                        userList += '<li style="padding:3px 0"><img src="' + flow_data[a].user_id_info[b].thumb + '" style="width:24px; height:24px; border-radius:50%; margin-right:8px;" />' + flow_data[a].user_id_info[b].name + '</li>';
                                    }
                                }
                                flowLi += '<li class="layui-timeline-item">\
								<i class="layui-icon layui-timeline-axis">&#xe63f;</i>\
								<div class="layui-timeline-content">\
								  <p class="layui-timeline-title"><strong>第' + (a + 1) + '级审批</strong>' + sign_type + '</p>\
								  <ul>' + userList + '</ul>\
								</div>\
							</li>';
                            }
                            formHtml = '<td class="layui-td-gray">审批流程</td>\
									<td colspan="7">\
										<ul id="flowList" class="layui-timeline">' + flowLi + '</ul>\
									</td>';
                            $('#flow_tr').html(formHtml);
                        }
                    }
                }
            })
        });


        //选择关联的公司
        $('.license-picker').on('click', function () {
            let that = $(this);
            let callback = function (data) {
                $('[name="company_name"]').val(data.company_name);
                $('[name="company_id"]').val(data.id);


            }
            oaTool.outsidPicker(callback);
        });
    }
</script>
{/block}
<!-- /脚本 -->